﻿using MediatR;
using Sgr.UPMS.Domain.Departments;
using Sgr.UPMS.Domain.Users;
using Sgr.UPMS.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xunit.Sgr.EntityFrameworkCore
{
    public class TestDepartmentNameChangedDomainEventHandle : INotificationHandler<DepartmentChangedDomainEvent>
    {
        public const string HandleDepteName = "B05CC714-9372-C303-FD1D-D1CD5CBB6FBF";

        private readonly IDepartmentRepository _repository;

        public TestDepartmentNameChangedDomainEventHandle(IDepartmentRepository repository)
        {
            _repository = repository;
        }

        public async Task Handle(DepartmentChangedDomainEvent notification, CancellationToken cancellationToken)
        {
            var dept = await _repository.GetAsync(notification.DepartmentId, cancellationToken);
            if (dept != null)
            {
                //if (dept.Name.Contains(HandleDepteName))
                //{
                //    dept.ChangeName(notification.DepartmentName + " +1");
                //    await _repository.UpdateAsync(dept);
                //}
            }
        }
    }
}